var express = require('express');
var rawMaterialRouter = express.Router();
let SQLQuery = require('../utils/query.js');


rawMaterialRouter.post('/client/rawMaterialList', async function (req, res) {
  try {
    let queryObj = req.body;
    var sql = 'select * from raw_material';
    // var addSqlParams = [queryObj.name, queryObj.subject, queryObj.phone, queryObj.message, req.headers['x-forwarded-for'] ? req.headers['x-forwarded-for'].split(',').pop().trim() : '0.0.0.0', new Date()];
    let result = await SQLQuery.query(sql)
    res.send(global.common.resJson(0, 'success', result))

  } catch (err) {
    res.send(err);
  }

})


rawMaterialRouter.post('/client/addRawMaterial', async function (req, res) {
  try {
    let queryObj = req.body;

    var addSql = 'insert into raw_material(rawMaterial,rawMaterialType,manufacturers,manufacturersPhone,rawMaterialPrice,manufacturersAdress,preservation,Homologous,rawMaterialImg,unit,remark) values(?,?,?,?,?,?,?,?,?,?,?)';
    var addSqlParams = [queryObj.name, queryObj.subject, queryObj.phone, queryObj.message, req.headers['x-forwarded-for'] ? req.headers['x-forwarded-for'].split(',').pop().trim() : '0.0.0.0', new Date()];
    let result = await SQLQuery.query(addSql, addSqlParams)
    res.send(global.common.resJson(0, 'success', result))

  } catch (err) {
    res.send(err);
  }

})

module.exports = rawMaterialRouter;